//
//  AppDelegate+Category.m
//  WBBaseProject
//
//  Created by 吴斌 on 2017/6/27.
//  Copyright © 2017年 吴斌. All rights reserved.
//

#import "AppDelegate+Category.h"

/*! 用RDVTabBarController，使用此头文件 */
#import "BaseNavigationController.h"

/*! 用RDVTabBarController，使用此头文件 */
#import <AFNetworkActivityIndicatorManager.h>
#import <AFNetworkReachabilityManager.h>

@interface AppDelegate()

/*! 监测是否有网络 */
@property (nonatomic, readonly) AFNetworkReachabilityStatus netReachStatus;

@end

@implementation AppDelegate (Category)

/*! 网络监测 */
- (void)wb_networkActivityIndicator{
    // 当使用AF发送网络请求时,只要有网络操作,那么在状态栏(电池条)wifi符号旁边显示  菊花提示
    [AFNetworkActivityIndicatorManager sharedManager].enabled = YES;
    
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status)
        {
            case AFNetworkReachabilityStatusReachableViaWiFi:
                DebugLog(@"当前是WiFi环境！");
                break;
            case AFNetworkReachabilityStatusNotReachable:
                DebugLog(@"当前无网络！");
                break;
            case AFNetworkReachabilityStatusUnknown:
                DebugLog(@"当前网络未知！");
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                DebugLog(@"当前是蜂窝网络！");
                break;
                
            default:
                break;
        }
    }];
    
    // 开启网络检测
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    
    // 网络活动发生变化时,会发送下方key 的通知, 可以在通知中心中添加检测
    // AFNetworkingReachabilityDidChangeNotification
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"
        [[NSNotificationCenter defaultCenter] addObserver:self selector:nil name:AFNetworkingReachabilityDidChangeNotification object:nil];
#pragma clang diagnostic pop
}

- (BOOL)isOnLine{
    AFNetworkReachabilityStatus netReachStatus = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
    switch (netReachStatus) {
        case AFNetworkReachabilityStatusUnknown:
        case AFNetworkReachabilityStatusNotReachable:{
            return NO;
            break;
        }
        case AFNetworkReachabilityStatusReachableViaWWAN:
        case AFNetworkReachabilityStatusReachableViaWiFi: {
            return YES;
            break;
        }
    }
}


@end
